package com.niit.az;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Memorandum extends AppCompatActivity {

    SharedPreferences spMemorandum;
    SharedPreferences spMemorandumTime;
    private TextView tv_memorandum_show;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_memorandum);
        Button write = findViewById(R.id.btnWrite);
        Button read = findViewById(R.id.btnRead);
        tv_memorandum_show = findViewById(R.id.tv_memorandum_show);

        write.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText memorandum = findViewById(R.id.et_memorandum);
                EditText memorandumTime = findViewById(R.id.et_memorandum_time);
                spMemorandum = getSharedPreferences("memorandum", Context.MODE_PRIVATE);
                spMemorandumTime = getSharedPreferences("memorandumTime",Context.MODE_PRIVATE);
                SharedPreferences.Editor editorMemorandum = spMemorandum.edit();
                editorMemorandum.putString("memorandum",memorandum.getText().toString());
                SharedPreferences.Editor editorMemorandumTime = spMemorandumTime.edit();
                editorMemorandumTime.putString("memorandumTime",memorandumTime.getText().toString());
                editorMemorandum.commit();
                editorMemorandumTime.commit();
            }
        });

        read.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences memorandum = getSharedPreferences("memorandum",Context.MODE_PRIVATE);
                SharedPreferences memorandumTime = getSharedPreferences("memorandumTime",Context.MODE_PRIVATE);
                String strMemorandum = memorandum.getString("memorandum","");
                String strMemorandumTime = memorandumTime.getString("memorandumTime","");
                tv_memorandum_show.setText(strMemorandum);
                Toast.makeText(Memorandum.this,"您创建备忘录的时间为："+strMemorandumTime,Toast.LENGTH_LONG).show();
            }
        });
    }
}